package com.leyou.item.web;


import com.leyou.item.dto.CategoryDTO;


import com.leyou.item.service.CategoryService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {


    @Autowired
    private CategoryService categoryService;

/*    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDTO>> queryCategoryByParentId(@RequestParam("pid") Long pid) {


        //根据父类id 查询集合
        return ResponseEntity.ok( categoryService.query().eq("parent_id", pid).list() );

    }*/


    /**
     * todo: 根据父类目id，查询子类目的集合
     *
     * @param pid
     * @return
     */
    @GetMapping("/of/parent")
    public List<CategoryDTO> findCategoryByPId(@Param("pid") Long pid) {
       // System.out.println(pid + "!!!!!!!!!!!!");
        return categoryService.findCategoryById(pid);

    }


    /**todo:根据分类id，查询商品分类
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public CategoryDTO findCategoryDTOById(@PathVariable("id") Long id) {
       // System.out.println(id+"!!!!!!!!!");
       return categoryService.findCategoryDTOById(id);


    }


    /**
     * todo:根据分类id的集合，查询商品分类的集合
     * @param ids
     * @return
     */

    @GetMapping("/list")
    public List<CategoryDTO> listCategoryByIds(@RequestParam ("ids")List<Long>ids){

        return categoryService.listCategoryByIds(ids);
    }


    /**
     * todo:根据品牌id，查询商品分类的集合
     * @param bid
     * @return
     */
    @GetMapping("/of/brand")
    public List<CategoryDTO> listCategoryByBrandId(@RequestParam("id") Long bid){


        return categoryService.listCategoryByBrandId(bid);
    }



   //public ResponseEntity






}
